/*
 * Copyright 2012 JBoss Inc Licensed under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package com.fplanning.planner;

import java.util.List;

import org.drools.planner.config.SolverFactory;
import org.drools.planner.config.XmlSolverFactory;
import org.drools.planner.core.Solver;
import org.drools.planner.examples.cloudbalancing.domain.CloudBalance;
import org.drools.planner.examples.cloudbalancing.domain.CloudComputer;
import org.drools.planner.examples.cloudbalancing.domain.CloudProcess;
import org.drools.planner.examples.cloudbalancing.persistence.CloudBalancingGenerator;

import com.fplanning.planner.domain.FISlice;
import com.fplanning.planner.domain.FinancialPlan;
import com.fplanning.planner.domain.YearlyPlan;

public class FPlannerMain
{

    public static void main(String[] args)
    {
        // Build the Solver
        SolverFactory solverFactory = new XmlSolverFactory(
                "/com/fplanning/planner/solver/fPlannerSolverConfig.xml");
        Solver solver = solverFactory.buildSolver();

        FinancialPlan unsolvedFinancialPlan = FinancialPlanGenerator
                .generatePlan();

        // Solve the problem
        solver.setPlanningProblem(unsolvedFinancialPlan);
        solver.solve();
        FinancialPlan solvedFinancialPlan = (FinancialPlan) solver
                .getBestSolution();

        // Display the result
        System.out.println("\nSolved financial plan:\n"
                + toDisplayString(solvedFinancialPlan));
    }

    public static String toDisplayString(FinancialPlan plan)
    {
        StringBuilder displayString = new StringBuilder();
        for (YearlyPlan year : plan.getYearlyPlanList())
        {
            displayString.append(year.toString());
            displayString.append('\n');

        }
        return displayString.toString();
    }

}
